package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njtoyo.taxi.admin.mapper.master.entity.CallPrepayRule;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.call_prepay_rule.CallPrepayFencePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.call_prepay_rule.CallPrepayFenceWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.call_prepay_rule.CallPrepayRuleAddUpdateWrapper;
import com.njtoyo.taxi.admin.service.business.CallPrepayRuleService;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 行程预付费
 */
@RestController
@RequestMapping("/business/operation-rule/call-prepay-rule")
public class CallPrepayRuleController {

    @Autowired
    private CallPrepayRuleService callPrepayRuleService;


    @GetMapping("/list")
    public RestResult list(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                           @RequestParam(value = "size", required = false, defaultValue = "15") Integer size,
                           @RequestParam(value = "customerRegionName", required = false) String customerRegionName) {
        return callPrepayRuleService.list(current, size, customerRegionName);
    }


    @PostMapping("/add")
    public RestResult add(@RequestBody CallPrepayRuleAddUpdateWrapper addWrapper) {
        return callPrepayRuleService.add(addWrapper);
    }

    @PostMapping("/updateById")
    public RestResult updateById(@RequestBody CallPrepayRuleAddUpdateWrapper addWrapper) {
        return callPrepayRuleService.updateById(addWrapper);
    }


    @PostMapping("/updateActive")
    RestResult updateActive(@RequestBody CallPrepayRule callPrepayRule) {
        if (ObjectUtil.isNull(callPrepayRule.getId())) {
            return RestResult.failed("缺少必要参数:ID");
        }
        return callPrepayRuleService.updateActive(callPrepayRule);
    }


    /**
     * 添加围栏
     *
     * @param callPrepayRule
     * @return
     */
    @PostMapping("/addFence")
    RestResult addFence(@RequestBody CallPrepayFenceWrapper callPrepayRule) {
        if (ObjectUtil.isNull(callPrepayRule.getRuleId())) {
            return RestResult.failed("缺少必要参数:ID");
        }
        return callPrepayRuleService.addFence(callPrepayRule);
    }

    @DeleteMapping("/delete/{id}")
    RestResult deleteById(@PathVariable("id") Long id) {
        if (ObjectUtil.isNull(id)) {
            return RestResult.failed("缺少必要参数:ID");
        }
        return callPrepayRuleService.deleteById(id);
    }


//    @DeleteMapping("/delete/mongo/{mongoId}")
//    RestResult deleteMongoById(@PathVariable("mongoId") String mongoId) {
//        if (StrUtil.isBlank(mongoId)) {
//            return RestResult.failed("缺少必要参数:ID");
//        }
//        return callPrepayRuleService.deleteMongoById(mongoId);
//    }


    @GetMapping("/info/{id}")
    RestResult getInfoById(@PathVariable("id") Long id) {
        if (ObjectUtil.isNull(id)) {
            return RestResult.failed("缺少必要参数:ID");
        }
        return callPrepayRuleService.getInfoById(id);
    }
}
